# -*- coding: utf-8 -*-

from utils.operators.spark_submit import SparkSubmitOperator
from datetime import timedelta
from jms.dim import jms_dim__dim_lmdm_sys_network, jms_dim__dim_lmdm_sys_first_code
from jms.dwd.oms.dwd_oms_waybill_dt import jms_dwd__dwd_oms_waybill_dt
from jms.ods import jms_ods__tab_barscan_centerarrival, jms_ods__tab_barscan_centersend, \
    jms_ods__tab_barscan_difficult, jms_ods__tab_barscan_unloading
from jms.ods import jms_ods__yl_tmsnew_tms_shipment, jms_ods__tms_branch_shipment, \
    jms_ods__yl_tmsnew_branch_shipment, jms_ods__yl_tmsnew_branch_shipment_stop

jms_dm__dm_cn_export_center_store_new_detail_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_cn_export_center_store_new_detail_dt',
    pool_slots=10,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dm__dm_cn_export_center_store_new_detail_dt_{{ execution_date | date_add(-1) | cst_ds }}',  # yarn 任务名称
    driver_memory='16G',
    driver_cores=4,
    executor_memory='12G',
    executor_cores=8,
    num_executors=50,
    email=['lukunming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    conf={'spark.executor.memoryOverhead': '5G',
          'spark.default.parallelism': 1600,
          'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          },
    hiveconf={
        'hive.optimize.bucketmapjoin': 'true',
        'hive.optimize.bucketmapjoin.sortedmerge': 'true',
        'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat'
    },
    java_class='com.yunlu.bigdata.jobs.export.ExportCenterStoreDetailNew',  # spark 主类
    application='hdfs:///scheduler/jms/spark/lyx/ExportCenterStoreDetail/jobs-1.0-SNAPSHOT-jar-with-dependencies.jar',
    # spark jar 包
    application_args=['{{ execution_date | date_add(-1) | cst_ds }}'],
    # 参数dt 2020-10-26
    execution_timeout=timedelta(hours=3),
    retries=0,
)

# 设置依赖
jms_dm__dm_cn_export_center_store_new_detail_dt << [
    jms_ods__tab_barscan_centerarrival,
    jms_ods__tab_barscan_unloading,
    jms_ods__yl_tmsnew_tms_shipment,
    jms_ods__tms_branch_shipment,
    jms_ods__yl_tmsnew_branch_shipment,
    jms_ods__yl_tmsnew_branch_shipment_stop,
    jms_dwd__dwd_oms_waybill_dt,
    jms_dim__dim_lmdm_sys_network,
    jms_dim__dim_lmdm_sys_first_code,
    jms_ods__tab_barscan_centersend,
    jms_ods__tab_barscan_difficult,
]
